﻿using HealthcareSystem.API.Write.Application.Command.TeamCommand;
using HealthcareSystem.Domain.BasicSettings.Team;
using MediatR;
using Microsoft.EntityFrameworkCore;
using WeekExam.PassPort.ErrorCode;
using WeekExam.PassPort.Infrastructure.Interface;

namespace HealthcareSystem.API.Write.Application.CommandHandel.TeamCommandHandler
{
    /// <summary>
    /// 团队逻辑删除请求
    /// </summary>
    public class DeleteTeamCommandHandler : IRequestHandler<DeleteTeamCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<TeamTable> teamRep;

        public DeleteTeamCommandHandler(IBaseRepository<TeamTable> teamRep)
        {
            this.teamRep = teamRep;
        }

        public async Task<ApiResult<int>> Handle(DeleteTeamCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result=new ApiResult<int>();
            result.Code = ResultCode.Success;
            result.Message = ResultCode.查询成功.ToString();
            var res=teamRep.GetAll().FirstOrDefault(x=>x.TeamId==request.TeamId);
            res.IsDelete=true;
            await teamRep.UpdAsync(res);
            return await Task.FromResult(result);
        }
    }
}
